package com.xuhuan.thread.study2.pool;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author huan.xu
 * @date 2021/9/30 14:38
 * @description 线程池案例
 */
public class ThreadPoolDemo1 {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        try {
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                executorService.execute(() ->
                        System.out.println(Thread.currentThread().getName() + "在执行")
                );
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executorService.shutdown();
        }

    }
}
